﻿@model FairyWorld.Models.Fold

@{
    ViewBag.Title = "Music";
    Layout = "~/Views/Shared/UserLayout.cshtml";
}

<script>
    $(document).ready(function () {
        $("#musicli").attr("class", "active");
    })
    function update(message) {
        $.post("/User/Music", { "op": message },
        function (data) {
   //         alert("here");
            var str = '<tr>'+
        '<th class="span1">类型</th>'+
        '<th class="span2">名称</th>'+
        '<th class="span2">操作</th>'+
        '<th class="span2">大小(kb)</th>'+
        '<th class="span2">上传时间</th>'+
        '<th class="span2">下载次数</th>'+
        '<th class="span2">在线播放</th></tr>';
            for (item = 0; item < data.folds.length; ++item) {
                str += '<tr><td><img src="../../Content/image/icon/folder.png" style="width:30px"/>'
                +'</td><td><a onclick="update(\'+' + data.folds[item].foldname + '\')">' + data.folds[item].foldname + '</a></td>'
                    + '<td><a onclick=\'deletef("' + data.folds[item].foldname + '", 1)\'>删除</a></td><td></td><td></td><td></td><td></td></tr>';
            }
            for (item = 0; item < data.files.length; ++item) {
                if (data.files[item].tag == 1) {
                    var fname = data.files[item].filename;
                    var ex = fname.substr(fname.lastIndexOf(".") + 1, 3);
                    ex = ex.toLowerCase();
                    var originTime = data.files[item].createTime;
                    str += '<tr><td><img src="../../Content/image/icon/music.png" style="width:30px"/>'
                        + '</td><td>' + data.files[item].filename + '</td><td><a onclick=\'deletef("'
                        + data.files[item].filename + '",1)\'>删除</a>&nbsp;|&nbsp;'
                    + '<a href="/User/Download?name=' + data.files[item].filename + '&tag=1">下载</a></td>';
                    str += '<td>' + (data.files[item].size / 1024.0).toFixed(2) + '</td>'
                         + '<td>' + originTime.substr(0, originTime.indexOf(" ")) + '</td>'
                         + '<td>' + data.files[item].hot + '</td>';
                    if (ex == "mp3") {
                        str += '<td><a><img src="../../Content/image/icon/playmusic.jpg" onclick="play(\'' + data.files[item].url + '\')" style="width:30px"/></a></td>';
                    } else {
                        str += '<td></td>';
                    }
                }
            }
            document.getElementById("content").innerHTML = str;
        });
    }
 
    function play(musicSrc) {
        var player = document.getElementById("player");
        player.src = "../../" + musicSrc;
        player.play();
    }
</script>

<style type="text/css">
        .textstyle1
        {
            color: Red;
            font-weight: bold;
        }
        .textstyle2
        {
            color: Green;
            font-weight: bold;
        }
        .wrapper{ 
	    width:930px; 
	    background-color:#fff; 
	    position:relative;	    
	    box-shadow:1px 1px 4px rgba(0,0,0,0.4); 
	    -moz-box-shadow:1px 1px 4px rgba(0,0,0,0.4);
        -webkit-box-shadow: 1px 1px 4px rgba(0,0,0,.4);
        padding:20px;
	    }
 </style>



<h3>音乐</h3>
<div class="wrapper">
<div class="span4" style="float:left; padding-bottom:15px">
    <audio id="player" controls="controls"></audio>
</div>
<table id="content" class="table table-hover" style="font-family:'Arial Rounded MT', 'Microsoft YaHei'">
    <tr>
        <th class="span1">类型</th>
        <th class="span2">名称</th>
        <th class="span2">操作</th>
        <th class="span2">大小(kb)</th>
        <th class="span2">上传时间</th>
        <th class="span2">下载次数</th>
        <th class="span2">在线播放</th>
    </tr>
    @foreach (var items in Model.folds)
    {
        <tr>
            <td>
                <img src="../../Content/image/icon/folder.png" style="width:30px"/>
            </td>
            <td>
                <a onclick="update('+@items.foldname')">@items.foldname</a>
            </td>
            <td>
                <a onclick='deletef("@items.foldname", 1)'>删除</a>
            </td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    }
    @foreach (var items in Model.files)
    {
        if (items.tag == 1)
        {
            var ex = items.filename.Substring(items.filename.LastIndexOf(".") + 1);
            ex = ex.ToLower();
            <tr>
                <td>
                    <img src="../../Content/image/icon/music.png" style="width:30px"/>
                </td>
                <td>
                    @items.filename
                </td>
                <td><a onclick='deletef("@items.filename", 1)'>删除</a>&nbsp;|
                    @Html.ActionLink("下载", "Download", new { name = items.filename, tag = 1 })</td>
                <td>@{var fsize = items.size / 1024.0; fsize = Math.Round(fsize, 2);} @fsize</td>
                <td>@items.createTime.Substring(0, items.createTime.IndexOf(" "))</td>
                <td>@items.hot</td>

                <td>
                    @if(ex == "mp3"){
                    <a><img src="../../Content/image/icon/playmusic.jpg" onclick='play("@items.url")' style="width:30px"/></a>
                    }
                </td>
            </tr>
        }
    }
</table>

<a onclick="update('-')">上一层</a>
<div class="input-append" style="margin-top:10px">
    <input name="fold" id="newfold" type="text" placeholder="文件夹名"/>
    <input type="button" class="btn" onclick="addfolder()" value="新建文件夹"/>
    <input type="hidden" name="tag" id="tag" value="1" />
</div>
<!--<form method="get" action="AddFile">添加文件: <input type='text' name='filename'><input type="submit" value="添加"/><input type="hidden" name="tag" value="1" /></form>-->

<div>
    <p>添加文件：</p>
    <p><input id="fileInput1" name="fileInput1" type="file"/></p>
    <p style="margin-top:5px;font-size:14px;font-weight:bold;">
    <a href="javascript:if(checkImport()){$('#fileInput1').uploadifySettings('scriptData',{'name':$('#test').val()});$('#fileInput1').uploadifyUpload();}">导入文件</a></p>
    <p style="margin-top:5px;font-size:14px;font-weight:bold;"><span id="result"></span></p>
</div> 

</div>